home *** CD-ROM | disk | FTP | other *** search
- /* rctngl.c ( rectangle ) */
- /* Entered by A. Wayner */
-
- # include <graphics.h>
- # include <stdlib.h>
-
- main()
- {
- int graphdriver = DETECT;
- int graphmode, x1, x2, y1, y2, maxx, maxy, maxcolor;
-
- /* Detect adapter type and */
- /* initialize graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc");
- outtextxy( 10, 10, "Random rectangles with 'rectangle' ");
-
- maxx = getmaxx() - 100;
- maxy = getmaxy() - 60;
- maxcolor = getmaxcolor();
- randomize(); /* Initialize random number generator */
-
- /* Exit when user presses a key */
- outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
- while( !kbhit())
- {
- /* Generate random points for the corners */
- x1 = random( maxx ) + 50;
- x2 = random( maxx ) + 50;
- y1 = random( maxy ) + 30;
- y2 = random( maxy ) + 30;
- setcolor( LIGHTCYAN );
-
- /* Now draw the rectangle */
- rectangle( min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2));
- }
-
- closegraph(); /* Exit graphics library */
-
- }